package com.anorak.betsy;

import cn.hutool.core.io.FileUtil;
import com.anorak.betsy.entity.Music;
import com.anorak.betsy.entity.Song;
import com.anorak.betsy.util.ConvertUtil;
import com.anorak.betsy.util.DownloadsUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * MusicFlit App!
 *
 * @author anorak
 */
public class App {
    public static void main(String[] args) throws Exception {
        Music music = new Music();
        if (StringUtils.isNotEmpty(args[0])) {
            music = ConvertUtil.convert(args[0]);
        } else {
            System.out.println("请检查您输入的参数!");
        }
        String QQPath = "/Users/anorak/Downloads/QQMusic/";
        List<File> fileList = FileUtil.loopFiles(QQPath);
        List<String> files = new ArrayList<>();
        for (File file : fileList) {
            if (file.isFile()){
                String n1 = file.getName().trim().replace(".mp3","")
                        .replace(".flac","");
                if ( n1.contains(" - ") ){
                    String[] string = n1.split(" - ");
                    files.add(string[string.length - 1]);
                }else {
                    files.add(n1);
                }
            }
        }
        List<String> songs = new ArrayList<>();
        for (Song song : music.getSongList()) {
            songs.add(song.getName());
        }

        List<String> songTemp = new ArrayList<>();
        for (String file : files) {
            if ( songs.contains(file) ){
                songTemp.add(file);
            }
        }
        songs.removeAll(songTemp);
        System.out.println(songTemp);

//        if (!music.getSongList().isEmpty()) {
//            DownloadsUtil.downloads(music);
//        }
    }
}
